DEFINITION MODULE MemoryMgr; (* W. Rohdewald / ETHZ / 15.2.85  *) 
                             (* Last modification 19.06.85 fxk *)

 (* GZCritical and GZSaveHnd are not implemented. *)

FROM SYSTEM IMPORT ADDRESS;
IMPORT MacBase;

EXPORT QUALIFIED MemFullErr,NilHandleErr,MemWZErr,MemPurErr,NoErr,
  MaxSize,
  Handle,THz,OsErr,
  SetApplBase,InitApplZone,InitZone,GetZone,SetZone,ApplicZone,SystemZone,
  CompactMem,PurgeMem,FreeMem,ResrvMem,MaxMem,TopMem,SetGrowZone,
  SetApplLimit,
  NewPtr,DisposPtr,GetPtrSize,SetPtrSize,PtrZone,
  NewHandle,DisposHandle,GetHandleSize,SetHandleSize,HandleZone,
  RecoverHandle,EmptyHandle,ReAllocHandle,
  HLock,HUnLock,HPurge,HNoPurge,MoreMasters,
  BlockMove,MemError,
  GZCritical,GZSaveHnd,GrowProc;

CONST
  MemFullErr    = -108;     (* Not enough room in heap zone *)
  NilHandleErr  = -109;     (* Master Pointer was NIL in HandleZone or other   *)
  MemWZErr      = -111;     (* WhichZone failed (applied to free block)        *)
  MemPurErr     = -112;     (* trying to purge a locked or non-purgeable block  *)
  NoErr         =  0;       (* All is well *)

  MaxSize       = 800000H;  (* Max data block LONGCARD is 512K bytes  *)

TYPE LONGCARD=ADDRESS;LONGINT=ADDRESS;

  Handle        = MacBase.Handle;(* pointer to a master pointer *)
  THz           = ADDRESS;       (* pointer to the start of a heap zone *)
  OsErr         = MacBase.OsErr;            (* error code *)
  GrowProc      = PROCEDURE (LONGCARD): LONGCARD;

PROCEDURE SetApplBase(startPtr: ADDRESS);
PROCEDURE InitApplZone();
PROCEDURE InitZone(grwProc:            GrowProc;
                   moreMasters:        INTEGER;
                   limitPtr,startPtr : ADDRESS);
PROCEDURE GetZone(): THz;
PROCEDURE SetZone(hz:THz);
PROCEDURE ApplicZone(): THz;
PROCEDURE SystemZone(): THz;
PROCEDURE CompactMem(cbNeeded: LONGCARD): LONGCARD;
PROCEDURE PurgeMem(cbNeeded: LONGCARD);
PROCEDURE FreeMem(): LONGCARD;
PROCEDURE ResrvMem(cbNeeded: LONGCARD);
PROCEDURE MaxMem(VAR grow: LONGCARD): LONGCARD;
PROCEDURE TopMem(): ADDRESS;

PROCEDURE SetGrowZone(growZone: GrowProc);
PROCEDURE SetApplLimit(zoneLimit: ADDRESS);

PROCEDURE NewPtr(byteCount: LONGCARD): ADDRESS;
PROCEDURE DisposPtr(p: ADDRESS);
PROCEDURE GetPtrSize(p: ADDRESS): LONGCARD;
PROCEDURE SetPtrSize(p: ADDRESS; newSize: LONGCARD);
PROCEDURE PtrZone(p: ADDRESS): THz;

PROCEDURE NewHandle(byteCount: LONGCARD): Handle;
PROCEDURE DisposHandle(h: Handle);
PROCEDURE GetHandleSize(h: Handle): LONGCARD;
PROCEDURE SetHandleSize(h: Handle; newSize: LONGCARD);
PROCEDURE HandleZone(h: Handle): THz;
PROCEDURE RecoverHandle(p: ADDRESS): Handle;
PROCEDURE EmptyHandle(h: Handle);
PROCEDURE ReAllocHandle(h: Handle; byteCount: LONGCARD);

PROCEDURE HLock(h: Handle);
PROCEDURE HUnLock(h: Handle);
PROCEDURE HPurge(h: Handle);
PROCEDURE HNoPurge(h: Handle);
PROCEDURE MoreMasters(): OsErr;

PROCEDURE BlockMove(srcPtr, destPtr: ADDRESS; byteCount: LONGCARD);
PROCEDURE MemError(): OsErr;

PROCEDURE GZCritical(): BOOLEAN;
PROCEDURE GZSaveHnd(): Handle;

END MemoryMgr.
